package com.nut.spp.api.client;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.spp.api.req.MemberCouponQueryReq;
import com.nut.spp.common.Holder;
import com.nut.spp.common.Result;
import com.nut.spp.entity.MemberCoupon;
import com.nut.spp.interceptor.ClientJwt;
import com.nut.spp.service.MemberCouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/client/memberCoupon")
public class MemberCouponController {

    @Autowired
    private MemberCouponService memberCouponService;

    @GetMapping("/list")
    public Result<IPage<MemberCoupon>> listPage(MemberCouponQueryReq req) {
        ClientJwt clientJwt = Holder.CLIENT_JWT_THREAD_LOCAL.get();
        req.setMemberId(clientJwt.getMemberId());
        return memberCouponService.listPage(req);
    }

    @GetMapping("/sendCoupon")
    public Result sendCoupon(@RequestParam Integer id, @RequestParam String mobile) {
        ClientJwt clientJwt = Holder.CLIENT_JWT_THREAD_LOCAL.get();
        return memberCouponService.sendCoupon(id, clientJwt.getMemberId(), mobile);
    }

}
